﻿CREATE PROCEDURE [dbo].[proc_ProjectExpenditure_GetList_MyProjects]
	(
		@Stext nvarchar(50),
		@UserName nvarchar(50),
		@StartIndex int,
		@EndIndex INT,
		@CompanyId int 
	)
AS
	;WITH list As
	(Select ROW_NUMBER() OVER (ORDER BY Id)AS Row,
		Id,
		PEId,
		ProjectName,
		Content,
		ApplyAmount,
		SubjectId,
		LaunchDate,
		IsNull(ManagerApprove,0) as ManagerApprove,
		ManagerApprovePerson,
		IsNull(ManagerApproveDate,'1900-01-01') as ManagerApproveDate,
		IsNull(FinanceApprove,0) as FinanceApprove,
		FinanceApprovePerson,
		IsNull(FinanceApproveDate,'1900-01-01') as FinanceApproveDate,
		Description,
		CompanyId,
		DepartmentId,
		(Select CompanyName From Company Where Id=ProjectExpenditure.CompanyId) As Company,
		(Select DName from Department Where Id=ProjectExpenditure.DepartmentId) As Department,
		(Select Title From Finance_Subject Where Id=ProjectExpenditure.SubjectId) As SubjectName
		From ProjectExpenditure Where UserName=@UserName AND (CompanyId=@CompanyId OR @CompanyId=0)  and (@Stext is null Or ProjectName like '%'+@Stext+'%')
	)
	Select *,(SELECT COUNT(1) FROM list) AS cid From list Where Row between @StartIndex and @EndIndex
	RETURN
